import myAxios from "@/utils/myAxios"

// 获取验证码
export function getVerCodeApi(width: number = 150, height: number = 40) {
  return myAxios<any, getVerCodeType>({
    url: "/admin/base/open/captcha",
    method: "get",
    params: {
      width,
      height
    }
  })
}

// 登录接口
export function loginApi(
  username: string,
  password: string,
  captchaId: string,
  verifyCode: string
) {
  return myAxios<any, loginType>({
    url: "/admin/base/open/login",
    method: "post",
    data: {
      username,
      password,
      captchaId,
      verifyCode
    }
  })
}

// 获取用户信息接口
export function getInfoApi() {
  return myAxios<any, getInfoType>({
    url: "/admin/base/comm/person",
    method: "get"
  })
}

// 获取用户权限菜单
export function getMenusApi() {
  return myAxios<any, getMenusType>({
    url: "/admin/base/comm/permmenu",
    method: "get"
  })
}

// 刷新token
export function refreshTokenApi(refreshToken: string | null) {
  return myAxios<any, refreshTokenType>({
    url: "/admin/base/open/refreshToken",
    method: "get",
    params: {
      refreshToken
    }
  })
}

// 获取用户列表
export function getUserListApi(page: number, size: number, keyWord?: string) {
  return myAxios<any, { list: userType[]; pagination: paginationType }>({
    url: "/admin/base/sys/user/page",
    method: "post",
    data: {
      page,
      size,
      keyWord
    }
  })
}

// 上传文件
export function uploadApi(file: File) {
  return myAxios<any, string>({
    url: "/admin/base/comm/upload",
    method: "POST",
    // PS
    headers: {
      "Content-Type": "multipart/form-data"
    },
    data: {
      file
    }
  })
}

// 退出登录
export function logoutApi() {
  return myAxios({
    url: "/admin/base/comm/logout",
    method: "post"
  })
}

// 增加用户
export function addUserApi(data: any) {
  return myAxios({
    url: "/admin/base/sys/user/add",
    method: "POST",
    data
  })
}

// 更新用户
export function updateUserApi(data: any) {
  return myAxios({
    url: "/admin/base/sys/user/update",
    method: "POST",
    data
  })
}

// 删除用户
export function deleteUserApi(ids: number[]) {
  return myAxios({
    url: "/admin/base/sys/user/delete",
    method: "post",
    data: {
      ids
    }
  })
}

/**
 * 获取权限与菜单
 */
export function getPermmenu() {
  return myAxios<any, IPermmenuResp>({
    url: '/admin/base/comm/permmenu',
    method: 'GET'
  })
}

/**
 * 获取菜单列表数据
 */
export function getMenuList() {
  return myAxios<any, IMenuListResp>({
    url: '/admin/base/sys/menu/list',
    method: 'POST'
  })
}

/**
 * 删除菜单
 */
export function delMenuList(data: any) {
  return myAxios({
    url: '/admin/base/sys/menu/delete',
    method: 'POST',
    data
  })
}

/**
 * 新增菜单
 */
export function addMenu(data: any) {
  return myAxios({
    url: '/admin/base/sys/menu/add',
    method: 'POST',
    data
  })
}

/**
 * 编辑菜单
 */
export function updateMenu(data: any) {
  return myAxios({
    url: '/admin/base/sys/menu/update',
    method: 'POST',
    data
  })
}

/**
 * 获取角色列表数据
 */
export function getRoleApi(data: IGetRoleParams) {
  return myAxios<any, IRoleListResp>({
    url: '/admin/base/sys/role/page',
    method: 'POST',
    data
  })
}

/**
 * 添加角色
 */
export function addRole(data: any) {
  return myAxios({
    url: '/admin/base/sys/role/add',
    method: 'POST',
    data
  })
}

/**
 * 更新角色
 */
export function updateRole(data: any) {
  return myAxios({
    url: '/admin/base/sys/role/update',
    method: 'POST',
    data
  })
}
